var t = require("../../../@babel/runtime/helpers/toConsumableArray");

require("../../../@babel/runtime/helpers/Objectvalues");

var e = require("../../../ec-canvas/echarts"), a = getApp();

Page({
    data: {
        charts_type: "1",
        listType: "0",
        activeDate: "0",
        dateList: [ {
            type: "0",
            title: "全部"
        }, {
            type: "1",
            title: "今日"
        }, {
            type: "2",
            title: "昨日"
        }, {
            type: "3",
            title: "本周"
        }, {
            type: "4",
            title: "上周"
        }, {
            type: "5",
            title: "本月"
        } ],
        Height: 0,
        LastHeight: 0,
        finished: !1,
        loading: !1,
        page: 1,
        is_expend_member: "",
        hasSwipeImage: !1,
        swipers: {},
        extension: {},
        chartsData: {},
        personnelList: [],
        expendList: [],
        orderList: [],
        language: {}
    },
    onLoad: function(t) {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {
        this.getData();
    },
    getData: function() {
        var t = this, e = a.getNetAddresss("plugin.public-fund.frontend.controllers.fund.index");
        wx.showLoading({
            title: "loading"
        }), a._getNetWork({
            url: e,
            data: {
                page: 1,
                date_type: this.data.activeDate
            },
            success: function(e) {
                if (wx.hideLoading(), 1 === e.data.result) {
                    var a = e.data.data, i = a.is_expend_member, n = a.set, s = a.head, r = a.middle, o = a.bottom, d = !!n && Object.values(n).some(function(t) {
                        return t.thumb;
                    });
                    t.setData({
                        is_expend_member: i,
                        hasSwipeImage: d,
                        swipers: n,
                        extension: s,
                        chartsData: r,
                        personnelList: o.fund_human_list.data
                    });
                    var l = o.fund_human_list;
                    (l.current_page >= l.last_page || l.data.length < l.per_page) && t.setData({
                        finished: !0
                    }), 1 == t.data.charts_type ? t.initEcharts() : t.initPieEcharts();
                } else wx.showToast({
                    title: e.data.msg
                });
            }
        });
    },
    changeDate: function(t) {
        var e = t.currentTarget.dataset.index;
        e != this.data.activeDate && (this.setData({
            activeDate: e
        }), this.initLoad(), 0 == this.data.listType ? this.getData() : (this.getData(), 
        this.getOrderData(this.data.listType)));
    },
    clickExtension: function(t) {
        var e = t.currentTarget.dataset.index;
        "amount_total" == e || "order_total" == e ? this.scrollAnchor("1") : "surplus_amount_total" == e ? wx.navigateTo({
            url: "/packageI/public_welfare_fund/record/record?type=2"
        }) : "expend_amount_total" == e || "expend_times_total" == e ? this.scrollAnchor("2") : "member_total" == e && this.scrollAnchor("0");
    },
    clickMemberAvatar: function(t) {
        this.memberId = t.detail, this.scrollAnchor("1");
    },
    scrollAnchor: function(t) {
        this.data.listType != t ? this.setData({
            listType: t
        }) : wx.createSelectorQuery().select(".list-box").boundingClientRect(function(t) {
            wx.pageScrollTo({
                scrollTop: t.top,
                duration: 300
            });
        }).exec();
    },
    toRecord: function() {
        wx.navigateTo({
            url: "/packageI/public_welfare_fund/record/record?type=1"
        });
    },
    toDonations: function() {
        wx.navigateTo({
            url: "/packageI/public_welfare_fund/donations/donations"
        });
    },
    setListType: function(t) {
        this.setData({
            listType: t.detail.name
        }), this.changeListType();
    },
    changeListType: function(t) {
        this.initLoad(), 0 == this.data.listType ? this.getPersonnelData(t) : this.getOrderData(this.data.listType, t);
    },
    imgHeight: function(t) {
        var e = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        parseInt(e) > this.data.LastHeight && (this.setData({
            Height: e
        }), this.data.LastHeight = parseInt(e));
    },
    getPersonnelData: function(t) {
        var e = this;
        if (this.data.finished || this.data.loading) return !1;
        this.setData({
            loading: !0
        });
        var i = a.getNetAddresss("plugin.public-fund.frontend.controllers.fund.index");
        a._getNetWork({
            url: i,
            data: {
                page: this.data.page,
                date_type: this.data.activeDate
            },
            success: function(a) {
                if (1 === a.data.result) {
                    var i = a.data.data.bottom.fund_human_list;
                    (i.current_page >= i.last_page || i.data.length < i.per_page) && e.setData({
                        finished: !0
                    });
                    var n = e.data.page > 1 ? e.data.personnelList.concat(i.data) : i.data;
                    e.setData({
                        personnelList: n,
                        page: ++e.data.page
                    }), "function" == typeof t && t();
                } else wx.showToast({
                    title: a.data.msg
                });
            },
            complete: function() {
                e.setData({
                    loading: !1
                });
            }
        });
    },
    getOrderData: function(t, e) {
        var i = this;
        if (this.data.finished || this.data.loading) return !1;
        this.setData({
            loading: !0
        });
        var n = a.getNetAddresss("plugin.public-fund.frontend.controllers.fund.amountList");
        a._getNetWork({
            url: n,
            data: {
                page: this.data.page,
                member_id: this.memberId,
                date_type: this.data.activeDate,
                change_type: t
            },
            success: function(a) {
                if (1 === a.data.result) {
                    var n = a.data.data ? a.data.data.list : {};
                    (n.current_page >= n.last_page || n.data.length < n.per_page) && i.setData({
                        finished: !0
                    }), 1 == t ? i.setData({
                        orderList: i.data.page > 1 ? i.data.orderList.concat(n.data) : n.data,
                        page: ++i.data.page
                    }) : i.setData({
                        expendList: i.data.page > 1 ? i.data.expendList.concat(n.data) : n.data,
                        page: ++i.data.page
                    }), "function" == typeof e && e();
                } else wx.showToast({
                    title: a.data.msg
                });
            },
            complete: function() {
                i.memberId = "", i.setData({
                    loading: !1
                });
            }
        });
    },
    tabChange: function(t) {
        this.setData({
            charts_type: t.detail.name
        }), 1 == this.data.charts_type ? this.initEcharts() : this.initPieEcharts();
    },
    initEcharts: function() {
        var a = this.selectComponent("#echats-income"), i = this.data.chartsData.income;
        console.log(this.data.chartsData);
        var n = i.map(function(t) {
            return t.count;
        }), s = {
            tooltip: {
                trigger: "axis"
            },
            grid: {
                right: "6%",
                left: "6%",
                bottom: "5%",
                containLabel: !0
            },
            legend: {
                data: [ "金额", "笔数" ]
            },
            xAxis: [ {
                type: "category"
            } ],
            yAxis: [ {
                type: "value",
                name: "金额",
                min: 0
            }, {
                type: "value",
                name: "笔数",
                min: 0,
                max: Math.max.apply(Math, t(n)) || 50,
                axisLabel: {
                    formatter: function(t, e) {
                        return Math.floor(t);
                    }
                }
            } ],
            dataset: {},
            series: [ {
                name: "金额",
                type: "bar",
                color: "#3b84f2",
                barWidth: 20
            }, {
                name: "笔数",
                type: "line",
                yAxisIndex: 1,
                color: "#ffc11e"
            } ]
        };
        s.dataset.dimensions = [ "date", "amount", "count" ], s.dataset.source = i, a.init(function(t, a, i) {
            var n = e.init(t, null, {
                width: a,
                height: i
            });
            return n.setOption(s), n;
        });
    },
    initPieEcharts: function() {
        var t = this.selectComponent("#echats-income-pie"), a = this.data.chartsData.expend, i = {
            color: [ "#3776e7", "#55c3f3" ],
            title: {
                x: 50,
                y: "69%",
                text: "",
                textStyle: {
                    fontSize: 12,
                    fontWeight: 400
                }
            },
            legend: {
                type: "plain",
                orient: "vertical",
                x: 20,
                y: "bottom",
                formatter: function(t) {
                    var e = a.find(function(e) {
                        return e.name == t;
                    });
                    return "".concat(t, "：").concat(e.amount, "元");
                }
            },
            series: [ {
                type: "pie",
                radius: [ "50%", "60%" ],
                center: [ "50%", "38%" ],
                labelLine: {
                    normal: {
                        length: 5
                    }
                },
                label: {
                    position: "outer",
                    alignTo: "edge",
                    margin: 10,
                    formatter: function(t, e, a) {
                        return t.name + "\n" + t.percent + "%";
                    }
                },
                data: []
            } ]
        };
        i.title.text = "收入总额：" + a[2].amount + "元", i.series[0].data = a.slice(0, 2).map(function(t) {
            return {
                name: t.name,
                value: parseFloat(t.amount.replace(",", ""))
            };
        }), t.init(function(t, a, n) {
            var s = e.init(t, null, {
                width: a,
                height: n
            });
            return s.setOption(i), s;
        });
    },
    onReachBottom: function() {
        0 == this.data.listType ? this.getPersonnelData() : this.getOrderData(this.data.listType);
    },
    jumpLink: function(t) {
        console.log(t.currentTarget.dataset);
        var e = t.currentTarget.dataset.link;
        if (!e) return !1;
        wx.reLaunch({
            url: e
        });
    },
    initLoad: function() {
        this.setData({
            page: 1,
            finished: !1,
            loading: !1
        });
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {}
});